package cn.wxq.daily.empdailymgforserve.controller;

import cn.wxq.daily.empdailymgforserve.domain.AbilitySingle;
import cn.wxq.daily.empdailymgforserve.mapper.AbilityQuestionBankDao;
import cn.wxq.daily.empdailymgforserve.model.Result;
import cn.wxq.daily.empdailymgforserve.model.StatusCode;
import cn.wxq.daily.empdailymgforserve.service.AbilitySingleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@CrossOrigin //跨越处理
@RestController
@RequestMapping("/abilityQuestionBank")
@Api(value = "AbilityQuestionBankController|题库管理")
public class AbilityQuestionBankController {
    @Autowired
    private AbilityQuestionBankDao abilityQuestionBankDao;

    @Autowired
    private AbilitySingleService abilitySingleService;

    /**
     * 将试卷中的题目放入到题库中
     * @param alityPaperId
     * @return
     */
    @RequestMapping(value = "/addquestionBank", method = RequestMethod.POST)
    @ApiOperation(value = "将试卷中的题目放入到题库中")
    public void addquestionBank(Integer alityPaperId ) {

        //通过试卷的id查询关联的题
        List<AbilitySingle> papersingles = abilitySingleService.papersingles(alityPaperId);
        //将题目存到题库中
        for (AbilitySingle papersingle : papersingles) {
            abilityQuestionBankDao.addquestionBank(papersingle);
        }
        //当single表中相关试题存入到题库中，删除single表中对应的试题
//        int row = abilitySingleService.deletePaper(alityPaperId);
        //删完试题之后，再将该试卷删除
//        testPaperService.deletePaper(tpid);
       /* if (row >0) {
            return new Result(true, StatusCode.OK, "新增成功");
        } else {
            return new Result(false, StatusCode.ERROR, "新增异常");
        }*/
    }
}
